#include "ConditionalEuclideanClusteringModel.h"

#include "core/AppDirectory.h"

namespace {
const QString UserFilename = "pcl.conditional_euclidean_clustering_model.json";
}

ConditionalEuclideanClusteringModel::ConditionalEuclideanClusteringModel()
    : BasePclModel()
{
    setPclHelpPage("https://pcl.readthedocs.io/projects/tutorials/en/master/conditional_euclidean_clustering.html");
}

ConditionalEuclideanClusteringModel& ConditionalEuclideanClusteringModel::get()
{
    static ConditionalEuclideanClusteringModel instance;
    if (instance.filename().isEmpty()) {
        instance.setFilename(AppDirectory::get().getAppDocFile(UserFilename));
        instance.load();
    }
    return instance;
}

void ConditionalEuclideanClusteringModel::fromJson(const QJsonObject& json, QStringList& errorList)
{
    BasePclModel::fromJson(json, errorList);

    pcdFile_ = json["pcdFile"].toString(pcdFile_);
    radiusSearch_ = json["radiusSearch"].toDouble(radiusSearch_);
}

QJsonObject ConditionalEuclideanClusteringModel::toJson() const
{
    QJsonObject json = BasePclModel::toJson();

    json.insert("pcdFile", QJsonValue(pcdFile_));
    json.insert("radiusSearch", QJsonValue(radiusSearch_));

    return json;
}
